from flask import Flask, render_template, request, flash
from flask_sqlalchemy import SQLAlchemy

app = Flask(__name__)
app.secret_key = 'qweqwe'
app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql://root:123456@127.0.0.1/my_flask'
#用户名密码
app.config['SQLALCHEMY_TRACK_MODIFICATIONS']=False
db = SQLAlchemy(app)
i = 2

class Role(db.Model):
    # 定义表名
    __tablename__ = 'roles'

    # 定义字段
    # db.Column表示是一个字段
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(16), unique=True)

class User(db.Model):
    __tablename__ = 'users'
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(16), unique=True)
    role_id = db.Column(db.Integer, db.ForeignKey('roles.id'))  # 表明这个是外键

@app.route('/', methods=['GET', 'POST'])
def login():
    print('dove')

if __name__ == '__main__':
    #保证每次运行都有一个干净的数据表
    #删除表
    db.drop_all()
    print('drop')
    #创建表
    db.create_all()
    print('create')

    app.run(debug=True)
##############################
#增
#role = Role(name='mzt')
#db.session.add(role)
#db.session.commit()
#############################
#改
#role.name='heima'  已经有了role对象
#db.session.commit()
#############################
#删
#delete
#commit




